package com.decent.core.alarm.config;

import com.decent.core.alarm.process.AlarmBusiness;
import com.decent.core.alarm.process.AlarmProcessExecutor;
import com.decent.core.alarm.process.AlarmProcessTemplate;
import com.decent.core.alarm.process.action.AlarmAction;
import com.decent.core.alarm.process.action.AlarmAfterParamCheckAction;
import com.decent.core.alarm.process.action.AlarmAssembleAction;
import com.decent.core.alarm.process.action.AlarmPreParamCheckAction;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * 报警内部配置
 *
 * @author menghx
 */
@Configuration
public class AlarmInternalConfig {


    /**
     * 普通报警发送执行流程
     * 1. 前置参数校验
     * 2. 组装参数
     * 3. 后置参数校验
     * 4. 请求发送渠道
     *
     * @return commonAlarmTemplate
     */
    @Bean("commonAlarmTemplate")
    public AlarmProcessTemplate commonAlarmTemplate() {
        AlarmProcessTemplate alarmProcessTemplate = new AlarmProcessTemplate();
        List<AlarmBusiness> processList = new ArrayList<>();

        // 前置参数校验
        processList.add(sendPreParamCheckAction());
        // 组装参数
        processList.add(sendAssembleAction());
        // 后置参数校验
        processList.add(sendAfterParamCheckAction());
        // 请求发送渠道
        processList.add(sendAction());

        alarmProcessTemplate.setProcessList(processList);
        return alarmProcessTemplate;
    }

    /**
     * pipeline流程控制器
     *
     * @return pipeline流程控制器
     */
    @Bean
    public AlarmProcessExecutor processController() {
        AlarmProcessExecutor alarmProcessExecutor = new AlarmProcessExecutor();
        alarmProcessExecutor.setAlarmProcessTemplate(commonAlarmTemplate());
        return alarmProcessExecutor;
    }

    /**
     * 发送报警前置参数校验Action
     *
     * @return 前置参数校验Action
     */
    @Bean
    public AlarmPreParamCheckAction sendPreParamCheckAction() {
        return new AlarmPreParamCheckAction();
    }

    /**
     * 发送报警建参数Action
     *
     * @return 组建参数Action
     */
    @Bean
    public AlarmAssembleAction sendAssembleAction() {
        return new AlarmAssembleAction();
    }

    /**
     * 发送报警后置参数校验Action
     *
     * @return 前置参数校验Action
     */
    @Bean
    public AlarmAfterParamCheckAction sendAfterParamCheckAction() {
        return new AlarmAfterParamCheckAction();
    }

    /**
     * 发送报警Action
     *
     * @return 发送报警Action
     */
    @Bean
    public AlarmAction sendAction() {
        return new AlarmAction();
    }

}
